<?php

require_once 'includes.php';

init();

if (isset($_GET["refreshManifest"])){
    dropManifest();
}

if (isset($_POST["responseType"])) {
    if ($_POST["responseType"] == "page") {
        $resolution = new Resolution();
        $resolution->handle();
    }
    if ($_POST["responseType"] == "form") {
        $resolution = new Resolution();
        $resolution->handleForm();
    }
    if ($_POST["responseType"] == ("createUser" || "removeUser" || "refreshManifest")) {
        $resolution = new Resolution();
        $resolution->handleCore();      
    }  
} else {
    if (isset($_GET["ajax"])) {
        $resolution = new Resolution();
        $resolution->handleAjax();
    } else {
        createPage();
    }
}

function createPage() {
    $pageFound = false;
    foreach (getTemplateManifest() as $value) {
        if (isset($_GET[$value[0]])) {
            if (strstr(getUser()->getRole(), $value[2])) {
                echo parse(loadTemplate($value[1]));
                $pageFound = true;
                break;
            }
        }
    }

    if (!$pageFound) {
        echo parse(loadTemplate(null, Settings::$defaultTemplate));
    }
}

finally();
?>
